<template lang="html">
  <section class="main-content">
    <se-content ref="search">
      <template>
        <se-form
          placeholder="搜索咨询顾问姓名"
          v-model="searchModel.param.advisorName"
        ></se-form>
        <se-form
          type="select"
          :options="returnCycleMethods"
          placeholder="搜索咨询顾问手机号"
          v-model="searchModel.param.advisorMobile"
        ></se-form>
        <se-form
          v-if=""
          type="select"
          placeholder="搜索产品类型"
          :options="typeOptions"
          v-model="searchModel.param.type"
        ></se-form>
        <se-form
          placeholder="搜索保单受理开始日期"
          v-model="searchModel.param.startAcceptDate"
        ></se-form>
        <se-form
          placeholder="搜索保单受理结束日期"
          v-model="searchModel.param.endAcceptDate"
        ></se-form>

      </template>
      <template slot="button">
        <el-button plain round type="primary" @click="query">查询</el-button>
      </template>
      <template slot="button">
        <el-button plain round type="primary" @click="query">重置</el-button>
      </template>
    </se-content>
    <nb-table
      :tableHeaders="tableHeaders"
      :tableData="tableData"
      :fixedOne="fixedOne"
      :clickData="clickData"
      :clickLast="clickLast"
      :format="format"
      @clickRight="clickRight"
      :row="row"
    >
    </nb-table>
    <pagination
      :total="total"
      :pageSize="searchModel.pageSize"
      :pageNo="searchModel.pageNo"
      @change="change"
    ></pagination>
  </section>
</template>

<script>
  import NbTable from '@/components/nb-table.vue'
  import Pagination from '@/components/pagination.vue'
  import SeContent from '@/components/se-content.vue'
  import SeForm from '@/components/se-form.vue'
  import Mixin from '@/common/mixin'
  /**
   *row:传递给跳转路由需要的整条
   */
  export default {
    data () {
      return {
        total: 0, // 当前页
        returnCycleMethods: [
          {
            label: '指定起息日',
            value: '1'
          }, {
            label: 'T + N起息',
            value: '2'
          }
        ],
        searchModel: {
          pageNo: 1, // 页码
          pageSize: 10, // 每页条数
          param: { // 搜索条件
            advisorName: '', // 搜索咨询顾问姓名
            advisorMobile: '', // 搜索咨询顾问手机号
            deptCode: '', // 搜索直属部门编号
            type: '', // 搜索产品类型
            startAcceptDate: '', // 搜索保单受理开始日期
            endAcceptDate: '', // 搜索保单受理结束日期
            startUnderwriteDate: '', // 搜索保单承保开始日期
            endUnderwriteDate: '', // 搜索保单承保结束日期
            startReceiptDate: '', // 搜索回执签署开始日期
            endReceiptDate: '' // 搜索回执签署结束日期
          }
        },
        tableHeaders: [
          {headerKey: 'advisorName', headerName: '咨询顾问姓名'},
          {headerKey: 'advisorMobile', headerName: '咨询顾问手机'},
          {headerKey: 'deptCode', headerName: '直属部门编号'},
          {headerKey: 'deptName', headerName: '所属部门'},
          {headerKey: 'totalAdvisorServiceCharge', headerName: '咨询服务费金额（元）'}
        ],
        tableData: [], // table数据
        fixedOne: false,
        clickOne: false,
        clickLast: true,
        categoryList: [],
        row: [],
        typeOptions: [{
          value: '0',
          label: '线上支付'
        }, {
          value: '1',
          label: '线上预约'
        }],
        format: [{
          need: 'advisorMobile',
          type: 'phone'
        }],
        thirdCompanyIdOptions: []
      }
    },
    components: {
      NbTable,
      Pagination,
      SeContent,
      SeForm
    },
    mixins: [Mixin],
    props: {
      clickData: Array
    },
    methods: {
      search () {
        this.$store.dispatch('SEARCH_CONSULTINGSERVICECHARGE', this.searchModel).then(res => {
          if (res.success) {
            this.tableData = res.data.list || []
            this.total = this.total ? this.total : res.data.totalCount
          } else {
            this.$message.error(res.msg)
          }
        })
      },
      type () {
        this.$store.dispatch('CATEGORY_CONSULTINGSERVICECHARGE', this.searchModel).then(res => {
          if (res.success) {
            this.categoryList = res.data.list || []
          } else {
            this.$message.error(res.msg)
          }
        })
      },
      query () {
        this.search()
      },
      change (index) {
        this.searchModel.pageNo = index
        this.search()
      },
      clickRight (data) {
        switch (data.type) {
          case 'onLine':
            this.$emit('edit', data.row.id)
            break
          case 'offLine':
            // this.revsort(data.row)
            break
          case 'revise':
            this.delete(data.row)
            break
          case 'reviseAgain':
            this.delete(data.row)
            break
          case 'sortBtn':
            // 增加跳转预约服务路由
            this.row = data.row
            this.$router.push({
              name: '',
              params: {
                id: ''
              }
            })
            break
        }
      },
      delete (row) {
        this.$confirm('确定删除该产品吗？', '提示信息', {type: 'warning'}).then(() => {
          this.$store.dispatch('DELETE_CONSULTINGSERVICECHARGE', {
            param: {
              value: row.id
            }
          }).then(res => {
            if (res.success) {
              this.$message.success('删除成功!')
              this.search()
            } else {
              this.$message.error(res.msg)
            }
          })
        })
      },
      onShelves (row) {
        this.$confirm('确定上架该产品吗？', '提示信息', {type: 'warning'}).then(() => {
          this.$store.dispatch('ONSHELVES_CONSULTINGSERVICECHARGE', {
            param: {
              value: row.id
            }
          }).then(res => {
            if (res.success) {
              this.$message.success('上架成功!')
              this.search()
            } else {
              this.$message.error(res.msg)
            }
          })
        })
      },
      offShelves (row) {
        this.$confirm('确定下架该产品吗？', '提示信息', {type: 'warning'}).then(() => {
          this.$store.dispatch('OFFSHELVES_CONSULTINGSERVICECHARGE', {
            param: {
              value: row.id
            }
          }).then(res => {
            if (res.success) {
              this.$message.success('下架成功!')
              this.search()
            } else {
              this.$message.error(res.msg)
            }
          })
        })
      },
      copy () {
        this.$message.success('已复制,可粘贴!')
      }
    },
    mounted () {
      // this.search()
      // this.type()
    }
  }
</script>

<style lang="scss">
</style>
